package org.dsc.amafinder.view;

import org.dsc.amafinder.ASearch;
import org.dsc.amafinder.R;
import org.dsc.sdk.DSC;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class AInfo extends Activity {
   protected TextView sugerencias;
   protected TextView resultadosBusquedas;
   protected TextView visitaBusquedas;
   protected TextView compraDesde;
   protected TextView visitaBlog;
   protected TextView urlBlog;
   Typeface fuente;
   String urlDelBlog = "http://Amafinder.blogspot.com.es/?m=1";

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.ainfo);

      fuente = Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf");

      sugerencias = (TextView) findViewById(R.id.Sugerencias);
      sugerencias.setTypeface(fuente);
      resultadosBusquedas = (TextView) findViewById(R.id.ResultadosBusquedas);
      resultadosBusquedas.setTypeface(fuente);
      visitaBusquedas = (TextView) findViewById(R.id.VisitaBusquedas);
      visitaBusquedas.setTypeface(fuente);
      compraDesde = (TextView) findViewById(R.id.CompraDesde);
      compraDesde.setTypeface(fuente);
      urlBlog = (TextView) findViewById(R.id.UrlBlog);
      urlBlog.setTypeface(fuente);
      urlBlog.setText(Html.fromHtml("<a href=" + urlDelBlog + ">Amafinder</a>"));

      urlBlog.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
            urlBlog.setTextColor(0xf89f0f);
            Uri uri = Uri.parse(urlDelBlog);
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(browserIntent);
         }
      });
      // estilo de actionbar (solo para api 11 en adelante)
      DSC.A(this).setUpActionBar();
      // poner adView
      DSC.A(this).createAdv(R.id.PubliLayoutInfo);
   }

   @Override
   protected void onResume() {
      super.onResume();
      DSC.A(this).resume();
   }

   @Override
   protected void onRestart() {
      super.onRestart();
      DSC.A(this).restart();
   }

   @Override
   public void onPause() {
      DSC.A(this).pause();
      super.onPause();
   }

   @Override
   public void onDestroy() {
      DSC.A(this).destroy();
      super.onDestroy();
   }

   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
      // para las demas cosas, se reenvia el evento al listener habitual
      return super.onKeyDown(keyCode, event);
   }

   /*
    * @ini-menu-action-bar
    */
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu items for use in the action bar
      getMenuInflater().inflate(R.menu.main_activity_actions, menu);
      menu.findItem(R.id.action_search).setIntent(new Intent(this, ASearch.class));
      menu.findItem(R.id.action_info).setIntent(new Intent(this, AInfo.class));
      //menu.findItem(R.id.action_favorites).setIntent(new Intent(this, AFavorites.class));
      return super.onCreateOptionsMenu(menu);
   }

   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.action_search:
     // case R.id.action_favorites:
         startActivity(item.getIntent());
         break;
      default:
         return super.onOptionsItemSelected(item);
      }
      return true;
   }
   /*
    * @end-menu-action-bar
    */
}
